﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _plants_vs_zombies
{
    /// <summary>
    /// 块的状态
    /// </summary>
    enum BlockStatus
    {
        豌豆射手,
        向日葵,
        空白,
        铲子,
        土豆
    }
    /// <summary>
    /// 块对象
    /// </summary>
    class Block
    {
        /// <summary>
        /// 定义block的块属性
        /// </summary>
        public BlockStatus Status { get; set; }

        /// <summary>
        /// 定义block的rectangle
        /// </summary>
        public Rectangle Rectangle { get; set; }

        /// <summary>
        /// 定义每个植物下一次行动的时间
        /// </summary>
        public DateTime NextGenerateTime { get; set; }

        /// <summary>
        /// 切图变量
        /// </summary>
        private int i = 1;

        /// <summary>
        /// 切图到点时间
        /// </summary>
        private DateTime changepicture { get; set; }

        /// <summary>
        /// 植物的生命值初始为20
        /// </summary>
        public int Plantlife = 0;

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="rectangle"></param>
        public Block(Rectangle rectangle)
        {
            //初始状态为空白
            Status = BlockStatus.空白;
            Rectangle = rectangle;
            //初始化每个植物下一次行动的时间
            NextGenerateTime = System.DateTime.Now.AddSeconds(2);
        }

        /// <summary>
        /// 绘制每一个block
        /// </summary>
        /// <param name="g"></param>
        public void Draw(Graphics g)
        {
            //test
            //g.DrawRectangle(new Pen(Color.Red), Rectangle);
            switch (Status)
            {
                case BlockStatus.豌豆射手:
                    if (System.DateTime.Now > changepicture)
                    {
                        switch (i)
                        {
                            case 1:
                                g.DrawImage(Properties.Resources.豌豆射手1, Rectangle);
                                break;
                            case 2:
                                g.DrawImage(Properties.Resources.豌豆射手2, Rectangle);
                                break;
                            case 3:
                                g.DrawImage(Properties.Resources.豌豆射手3, Rectangle);
                                break;
                            case 4:
                                g.DrawImage(Properties.Resources.豌豆射手4, Rectangle);
                                break;
                            case 5:
                                g.DrawImage(Properties.Resources.豌豆射手5, Rectangle);
                                break;
                            case 6:
                                g.DrawImage(Properties.Resources.豌豆射手6, Rectangle);
                                break;
                            case 7:
                                g.DrawImage(Properties.Resources.豌豆射手7, Rectangle);
                                break;
                            case 8:
                                g.DrawImage(Properties.Resources.豌豆射手8, Rectangle);
                                break;
                            case 9:
                                g.DrawImage(Properties.Resources.豌豆射手9, Rectangle);
                                break;
                            case 10:
                                g.DrawImage(Properties.Resources.豌豆射手10, Rectangle);
                                break;
                            case 11:
                                g.DrawImage(Properties.Resources.豌豆射手11, Rectangle);
                                break;
                            case 12:
                                g.DrawImage(Properties.Resources.豌豆射手12, Rectangle);
                                break;
                            case 13:
                                g.DrawImage(Properties.Resources.豌豆射手13, Rectangle);
                                break;
                            case 14:
                                g.DrawImage(Properties.Resources.豌豆射手14, Rectangle);
                                break;
                            case 15:
                                g.DrawImage(Properties.Resources.豌豆射手15, Rectangle);
                                //循环
                                i = 0;
                                break;
                            default:
                                break;
                        }
                        i++;
                        changepicture = System.DateTime.Now.AddSeconds(0.3);
                    }
                    else
                    {
                        switch (i - 1)
                        {
                            case 0:
                                g.DrawImage(Properties.Resources.豌豆射手15, Rectangle);
                                break;
                            case 1:
                                g.DrawImage(Properties.Resources.豌豆射手1, Rectangle);
                                break;
                            case 2:
                                g.DrawImage(Properties.Resources.豌豆射手2, Rectangle);
                                break;
                            case 3:
                                g.DrawImage(Properties.Resources.豌豆射手3, Rectangle);
                                break;
                            case 4:
                                g.DrawImage(Properties.Resources.豌豆射手4, Rectangle);
                                break;
                            case 5:
                                g.DrawImage(Properties.Resources.豌豆射手5, Rectangle);
                                break;
                            case 6:
                                g.DrawImage(Properties.Resources.豌豆射手6, Rectangle);
                                break;
                            case 7:
                                g.DrawImage(Properties.Resources.豌豆射手7, Rectangle);
                                break;
                            case 8:
                                g.DrawImage(Properties.Resources.豌豆射手8, Rectangle);
                                break;
                            case 9:
                                g.DrawImage(Properties.Resources.豌豆射手9, Rectangle);
                                break;
                            case 10:
                                g.DrawImage(Properties.Resources.豌豆射手10, Rectangle);
                                break;
                            case 11:
                                g.DrawImage(Properties.Resources.豌豆射手11, Rectangle);
                                break;
                            case 12:
                                g.DrawImage(Properties.Resources.豌豆射手12, Rectangle);
                                break;
                            case 13:
                                g.DrawImage(Properties.Resources.豌豆射手13, Rectangle);
                                break;
                            case 14:
                                g.DrawImage(Properties.Resources.豌豆射手14, Rectangle);
                                break;
                            case 15:
                                g.DrawImage(Properties.Resources.豌豆射手15, Rectangle);                             
                                break;
                            default:
                                break;
                        }
                    }
                    break;
                case BlockStatus.向日葵:
                    g.DrawImage(Properties.Resources.向日葵2, Rectangle);
                    break;
                case BlockStatus.土豆:
                    //画变化的土豆
                    if (Plantlife>140 && Plantlife<=220)
                    {
                        g.DrawImage(Properties.Resources.tudou1, Rectangle);
                    }
                    else if (Plantlife>70 && Plantlife<= 140)
                    {
                        g.DrawImage(Properties.Resources.tudou2, Rectangle);
                    }
                    else if (Plantlife>0 && Plantlife<=70)
                    {
                        g.DrawImage(Properties.Resources.todou3, Rectangle);
                    }
                    break;
            }
        }

    }
}
